import { ActionBase } from "../../ActionBase";

/**
 * 放置site Action
 */
export class ActionObserve  extends ActionBase<IActionCMD<"observe">>
{
    public execute(action: IActionCMD<"observe">): ActionCode 
    {
        
        const room = action.arg.entity as Required<Room>;
        
        if(!room)
        {
            return 0;
        }
        const rooms = action.arg.task.data.arg.rooms;
        while(rooms.length  )
        {
            if(Game.rooms[rooms[0]])
            {
                rooms.splice(0,1);
                ;
            }
            else 
            {
                const observes = room.getStructures(STRUCTURE_OBSERVER);
                if(observes.length>0)
                {
                    const code = observes[0].observeRoom(rooms[0]);
                   // room.log(`warn`,`侦察:[${rooms[0]}]`,`侦察结果`,code);
                    rooms.splice(0,1);
                    if(code != OK)
                    {
                        //room.log("warn",`房间[${rooms[0]}]侦察异常:${code}`);
                        
                    }
                   
                    break;
                }
                else 
                {
                    room.log(`warn`,`找不到OBSERVER`)
                }
            }
            break;
        }
        return 0;
    }
}